#include "CusMenu.h"
#include "BasicModule.h"
#include "qbasicdefs.h"
#include <QDebug>

CusMenu::CusMenu(QWidget *parent)
	: QMenu(parent)
{
	loadStyle();

	this->setWindowFlags(this->windowFlags() | Qt::FramelessWindowHint | Qt::NoDropShadowWindowHint);
	this->setAttribute(Qt::WA_TranslucentBackground);
}

CusMenu::CusMenu(const QString &bgColor, const QString &tc, int fw, int fs, int radius, QWidget *parent)
	: QMenu(parent), m_bgColor(bgColor), m_fontWeight(fw)
	, m_textColor(tc), m_fontSize(fs), m_radius(radius)
{
	loadStyle();

	this->setWindowFlags(this->windowFlags() | Qt::FramelessWindowHint | Qt::NoDropShadowWindowHint);
	this->setAttribute(Qt::WA_TranslucentBackground);
}

CusMenu::~CusMenu()
{
}

void CusMenu::setPos(const QPoint &pos)
{
	m_pos = pos;
}

void CusMenu::showEvent(QShowEvent *event)
{
	QMenu::showEvent(event);
	if (m_pos != QPoint(0,0)) {
		move(m_pos);
	}
}

void CusMenu::loadStyle()
{
	BASICMODELE;

	Q_WINDOW_LOAD_STYLE_EX(
		replace("[BG_COLOR]", m_bgColor).
		replace("[FONT_WEIGHT]", QString::number(m_fontWeight)).
		replace("[TEXT_COLOR]", m_textColor).
		replace("[FONT_SIZE]", QString::number(m_fontSize)).
		replace("[BORDER_RADIUS]", QString::number(m_radius))
	);
	qDebug() << "============CusMenu::loadStyle()======";
}
